package cn.tedu.ivos.dict.service.serviceImp;

import cn.tedu.ivos.dict.mapper.DictMapper;
import cn.tedu.ivos.dict.pojo.dto.DictParam;
import cn.tedu.ivos.dict.pojo.dto.DictQuery;
import cn.tedu.ivos.dict.pojo.entity.Dict;
import cn.tedu.ivos.dict.pojo.vo.DictVO;
import cn.tedu.ivos.dict.service.DictService;
import cn.tedu.ivos.dictoption.mapper.DictOptionMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DictServiceImpl implements DictService {

    @Autowired
    private DictMapper mapper;

    @Autowired
    private DictOptionMapper dictOptionMapper;

    @Override
    public List<DictVO> select(DictQuery dictQuery) {
        return mapper.select(dictQuery);
    }

    @Override
    public void add(DictParam dictParam) {
        Dict dict = new Dict();
        BeanUtils.copyProperties(dictParam,dict);
        if (dict.getId() == null)
        {
            dict.setCreateTime(new Date());
            mapper.add(dict);
        }else
        {
            dict.setUpdateTime(new Date());
            mapper.update(dict);
        }
    }

    @Override
    public void del(Long id) {
        Dict dict = new Dict();
        dict.setId(id);
        mapper.del(dict);
        dictOptionMapper.delectByDictId(id);


    }
}
